package com.gill.ftp.controller;

import com.gill.ftp.config.FtpConfig;
import com.gill.ftp.config.properties.FtpProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gill.ftp.util.FtpUtil;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;


@Slf4j
@RestController
@RequestMapping(value = "/ftp")
public class FtpController {

	@Autowired
	FtpUtil ftpUtil;

	@GetMapping("/upload")
	public String upload() throws FileNotFoundException {
		InputStream in = new FileInputStream("D:\\software\\source_code\\sample-project\\my-utils-repo\\ftp\\src\\main\\java\\demo\\asdasd.png");
		boolean result = ftpUtil.uploadFile("/a/b/c", "code.png", in);
		return result?"上传成功":"上传失败";
	}

	@GetMapping("/download")
	public String download(){
		String fileName = "/a/b/c/code.png";
		String localPath = "C:\\Users\\Administrator\\Desktop\\";
		boolean result = ftpUtil.downloadFile(fileName, localPath);
		return result?"下载成功":"下载失败";
	}

	@GetMapping("/delete")
	public String delete() {
		String fileName = "/a/b/c/code.png";
		boolean result = ftpUtil.deleteFile(fileName);
		return result?"删除成功":"删除失败";
	}


}
